package com.ruoyi.dl.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dl.domain.DlOrderDeduction;
import com.ruoyi.dl.service.IDlOrderDeductionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 扣款记录Controller
 * 
 * @author ruoyi
 * @date 2021-01-14
 */
@Controller
@RequestMapping("/dl/deduction")
public class DlOrderDeductionController extends BaseController
{
    private String prefix = "dl/deduction";

    @Autowired
    private IDlOrderDeductionService dlOrderDeductionService;

    @RequiresPermissions("dl:deduction:view")
    @GetMapping()
    public String deduction()
    {
        return prefix + "/deduction";
    }

    /**
     * 查询扣款记录列表
     */
    @RequiresPermissions("dl:deduction:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DlOrderDeduction dlOrderDeduction)
    {
        startPage();
        List<DlOrderDeduction> list = dlOrderDeductionService.selectDlOrderDeductionList(dlOrderDeduction);
        return getDataTable(list);
    }

    /**
     * 导出扣款记录列表
     */
    @RequiresPermissions("dl:deduction:export")
    @Log(title = "扣款记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DlOrderDeduction dlOrderDeduction)
    {
        List<DlOrderDeduction> list = dlOrderDeductionService.selectDlOrderDeductionList(dlOrderDeduction);
        ExcelUtil<DlOrderDeduction> util = new ExcelUtil<DlOrderDeduction>(DlOrderDeduction.class);
        return util.exportExcel(list, "deduction");
    }

    /**
     * 新增扣款记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存扣款记录
     */
    @RequiresPermissions("dl:deduction:add")
    @Log(title = "扣款记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DlOrderDeduction dlOrderDeduction)
    {
        return toAjax(dlOrderDeductionService.insertDlOrderDeduction(dlOrderDeduction));
    }

    /**
     * 修改扣款记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DlOrderDeduction dlOrderDeduction = dlOrderDeductionService.selectDlOrderDeductionById(id);
        mmap.put("dlOrderDeduction", dlOrderDeduction);
        return prefix + "/edit";
    }

    /**
     * 修改保存扣款记录
     */
    @RequiresPermissions("dl:deduction:edit")
    @Log(title = "扣款记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DlOrderDeduction dlOrderDeduction)
    {
        return toAjax(dlOrderDeductionService.updateDlOrderDeduction(dlOrderDeduction));
    }

    /**
     * 删除扣款记录
     */
    @RequiresPermissions("dl:deduction:remove")
    @Log(title = "扣款记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dlOrderDeductionService.deleteDlOrderDeductionByIds(ids));
    }
}
